package com.atguigu.eduService.controller;


import com.atguigu.commonUtils.Result;
import com.atguigu.commonUtils.ResultUtil;
import com.atguigu.eduService.entity.EduChapter;
import com.atguigu.eduService.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Chen Wen bo
 * @since 2021-07-22
 */
@Api(tags = "课程大纲")
@RestController
@RequestMapping("/eduService/chapter")
@CrossOrigin
public class EduChapterController {

    @Resource
    private EduChapterService eduChapterService;

    @ApiOperation("课程大纲查询")
    @GetMapping("/getChapterVideo/{courseId}")
    public Result<List<EduChapter>> getChapterVideo(@PathVariable String courseId){
        List<EduChapter> eduChapterList = eduChapterService.getChapterVideo(courseId);
        return ResultUtil.success(eduChapterList);
    }

    @ApiOperation("添加章节")
    @PostMapping("/addChapter")
    public Result<EduChapter> addChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.addChapter(eduChapter);
        return ResultUtil.success();
    }

    @ApiOperation("根据章节id查询")
    @GetMapping("/getChapterInfo/{chapterId}")
    public Result<EduChapter> getChapterInfo(@PathVariable String chapterId){
        EduChapter eduChapter = eduChapterService.getChapterInfo(chapterId);
        return ResultUtil.success(eduChapter);
    }



    @ApiOperation("修改章节")
    @PutMapping("/updateChapter")
    public Result<EduChapter> updateChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.updateChapter(eduChapter);
        return ResultUtil.success();
    }

    @ApiOperation("删除章节")
    @DeleteMapping("/deleteChapter/{chapterId}")
    public Result<EduChapter> deleteChapter(@PathVariable String chapterId){
        eduChapterService.deleteChapter(chapterId);
        return ResultUtil.success();
    }


}

